package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"navi-mumbai/app/rpc/game/internal/config"
	"navi-mumbai/app/rpc/model/pg/game"
	gameRedis "navi-mumbai/app/rpc/model/redis/game"
	"navi-mumbai/third/game/wz"
)

type ServiceContext struct {
	Config config.Config

	GameModel                    game.GameModel
	GameProviderModel            game.GameProviderModel
	UserOpenId1Model             game.UserOpenId1Model
	Order1Model                  game.Order1Model
	OrderStatModel               game.OrderStatModel
	ExchangeGameMoneyConfigModel game.ExchangeGameMoneyConfigModel

	RedisClient *redis.Redis
	GameRedis   *gameRedis.GameRedis
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.DB.DataSource) // sqlx.NewSqlConn(dbkey.PostgresDriverName, c.DB.DataSource)
	sc := ServiceContext{
		Config:                       c,
		GameModel:                    game.NewGameModel(sqlConn, c.Cache),
		GameProviderModel:            game.NewGameProviderModel(sqlConn, c.Cache),
		UserOpenId1Model:             game.NewUserOpenId1Model(sqlConn, c.Cache),
		Order1Model:                  game.NewOrder1Model(sqlConn, c.Cache),
		OrderStatModel:               game.NewOrderStatModel(sqlConn, c.Cache),
		ExchangeGameMoneyConfigModel: game.NewExchangeGameMoneyConfigModel(sqlConn, c.Cache),
	}

	sc.RedisClient = redis.MustNewRedis(c.Redis.RedisConf)
	sc.GameRedis = gameRedis.NewGameRedis(sc.RedisClient)

	//
	wz.InitHttpClient(c.WzConf.Id, c.WzConf.GuestId, c.WzConf.Secret, c.WzConf.Host, c.WzConf.DemoHost)
	return &sc
}
